package ws.very.util.lang

import scala.collection.convert.WrapAsJava
import java.{ util => jutl }
import scala.annotation.tailrec
import scala.util.Either

object Scala2JavaColl extends WrapAsJava {
  import java.{ util => jutl }
  @tailrec
  def apply(any: Any): Any =
    any match {
      case m: scala.collection.Map[_, _] => (m: jutl.Map[_, _])
      case s: scala.collection.Seq[_] => s: jutl.List[_]
      case s: scala.collection.Set[_] => s: jutl.Set[_]
      case s: scala.collection.Iterable[_] => asJavaCollection(s)
      case s: scala.collection.Iterator[_] => apply(s.toIterable)
      case Some(v) => apply(v)
      case None => null
      case Left(v) => apply(v)
      case Right(v) => apply(v)
      case t: (_, _) => apply(Map(t))
      case other => other
    }
}